package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/3/18 22:04
 * @since v1.0
 */
@Getter
public enum GainPublicErrcodeEnum {
    SUCCESS(1,"enum.gainPublicErrcode.attr.success"),


    DATA_ERROR(2,"enum.gainPublicErrcode.attr.data_error"),


    COMPANY_ERROR(3,"enum.gainPublicErrcode.attr.company_error"),


    NOT_PUBLIC(4,"enum.gainPublicErrcode.attr.not_public"),


    HAS_TEAM(5,"enum.gainPublicErrcode.attr.has_team"),


    OVER_NUM(6,"enum.gainPublicErrcode.attr.over_num"),


    PRE_PRINCIPAL(7,"enum.gainPublicErrcode.attr.pre_principal"),


    OVER_RATE(8,"enum.gainPublicErrcode.attr.over_rate"),
    ;

    private Integer code;
    private String attr;

    GainPublicErrcodeEnum(Integer code, String attr) {
        this.code = code;
        this.attr = attr;
    }

    public static GainPublicErrcodeEnum getByCode(Integer code) {
        for (GainPublicErrcodeEnum errcodeEnum : values()){
            if (Objects.equals(errcodeEnum.getCode(),code)){
                return errcodeEnum;
            }
        }
        return SUCCESS;
    }

    public String getAttr() {
        return I18nMessageUtil.getMessage(attr);
    }
}
